<template>
	<el-dialog
	  title="配置工时"
	  :visible.sync="visible"
	  :before-close="close"
	  :close-on-click-modal="false"
	  width="50%">
    <b>{{ standard.accordingToInside }}</b>
    <el-card style="margin-top: 20px">
      <el-table
        :data="items"
        border
        fit
        highlight-current-row
        style="width: 100%">
        <el-table-column
          prop="inspectionItemName"
          header-align="center"
          align="center"
          label="检验项目">
        </el-table-column>

        <el-table-column
        	header-align="center"
        	align="center"
        	label="工时1(小时)">
          <template slot-scope="scope">
            <el-input v-model="scope.row.manHourOne" size="mini" @change="saveOne(scope.$index,'manHourOne')" />
          </template>
        </el-table-column>

        <el-table-column
        	header-align="center"
        	align="center"
        	label="工时1(小时)">
          <template slot-scope="scope">
            <el-input v-model="scope.row.manHourTwo" size="mini" @change="saveOne(scope.$index,'manHourTwo')" />
          </template>
        </el-table-column>
      </el-table>
    </el-card>
	  <span slot="footer" class="dialog-footer">
      <el-button type="primary" class="pan-btn primary-btn" size="mini" @click="close">关闭</el-button>
  	</span>
	</el-dialog>
</template>

<script>
	import { getItemList,setProp } from "@/api/item"
  import { isBlank,humpToLine } from '@/common/js/utils'
  import { isPositiveNumber } from '@/common/js/validate'
	import { CODE_OK } from '@/common/js/config'
	export default {
		data() {
			return {
        isChangedData: false,
				visible: false,
        items: [],
        standard: {}
			}
		},
		props: ["childDataForm"],
		created() {
			if (!isBlank(this.childDataForm)) {
        this.standard = {
          insideInspectionStandardId: this.childDataForm.insideInspectionStandardId,
          accordingToInside: this.childDataForm.accordingToInside
        }
        this.getItems()
        this.visible = true
			}
		},
		methods: {
      getItems() {
        const params = {
          page: 1,
          limit: 9999,
          standardId: this.standard.insideInspectionStandardId
        }
        getItemList(params).then(res => {
          if (res.code === CODE_OK) {
          	this.items = res.page.list
          }else{
          	this.$message.error(res.msg)
          }
        })
      },
      saveOne(i,prop) {
        let value = this.items[i][prop]
        if (!isPositiveNumber(value)) {
          this.$message.error("请输入非负数")
          this.dataList[i][prop] = null
          return
        }
        const data = {
          id: this.items[i].inspectionItemId,
          key: humpToLine(prop),
          value: value
        }
        setProp(data).then(res => {
          if (res.code === CODE_OK) {
          	this.$message.success('保存成功')
            this.isChangedData = true
          }else{
          	this.$message.error(res.msg)
            this.dataList[i][prop] = null
          }
        })
      },
			close() {
				this.$emit('close')
        if (this.isChangedData) {
          this.$emit('refreshData')
        }
				this.visible = false
			}
    }
	}
</script>

<style>
</style>
